#!/bin/bash

# 检查.bashrc是否已包含自动加载命令
if ! grep -q "# Auto Navigation自动加载ROS环境" /root/.bashrc; then
    echo "" >> /root/.bashrc
    echo "# Auto Navigation自动加载ROS环境" >> /root/.bashrc
    echo "source /opt/ros/noetic/setup.bash" >> /root/.bashrc
    echo "source /root/catkin_ws/devel/setup.bash" >> /root/.bashrc
    echo "" >> /root/.bashrc
    echo "# Auto Navigation脚本路径" >> /root/.bashrc
    echo "export AUTO_NAV_SCRIPTS=/root/catkin_ws/src/auto_navigation/scripts" >> /root/.bashrc
    echo "alias build_map='bash \$AUTO_NAV_SCRIPTS/build_ndt_map_from_bag.sh'" >> /root/.bashrc
    echo "alias run_ndt='bash \$AUTO_NAV_SCRIPTS/run_ndt_localization_with_bag.sh'" >> /root/.bashrc
    echo "alias create_bag='bash \$AUTO_NAV_SCRIPTS/create_kitti_rosbag.sh'" >> /root/.bashrc
    echo "alias play_bag='bash \$AUTO_NAV_SCRIPTS/play_kitti_bag.sh'" >> /root/.bashrc
    echo "alias export_map='bash \$AUTO_NAV_SCRIPTS/export_map_simple.sh'" >> /root/.bashrc
    echo "alias git_upload='bash \$AUTO_NAV_SCRIPTS/upload_to_git.sh'" >> /root/.bashrc
    echo "alias git_upload_nav='bash \$AUTO_NAV_SCRIPTS/upload_auto_nav_only.sh'" >> /root/.bashrc
    echo "" >> /root/.bashrc
    
    echo "已添加ROS环境自动加载到.bashrc文件"
    echo "新增命令别名："
    echo "  build_map      - 构建NDT地图"
    echo "  run_ndt        - 运行NDT定位"
    echo "  create_bag     - 创建ROS bag"
    echo "  play_bag       - 播放ROS bag"
    echo "  export_map     - 导出点云数据"
    echo "  git_upload     - 上传整个src目录到Git仓库"
    echo "  git_upload_nav - 只上传auto_navigation目录到Git仓库"
    echo ""
    echo "请执行 'source ~/.bashrc' 使更改生效，或重新打开终端"
else
    echo "自动加载命令已存在于.bashrc文件中"
fi

# 确保脚本有执行权限
chmod +x /root/catkin_ws/src/auto_navigation/scripts/*.sh
chmod +x /root/catkin_ws/src/auto_navigation/scripts/*.py 